Skip to content

fix(provision): write managed hook scripts atomically at 0o755#143

Merged
CryptoJones merged 1 commit into
mainfrom
fix/atomic-hook-mode
Jul 2, 2026
Merged

fix(provision): write managed hook scripts atomically at 0o755#143
CryptoJones merged 1 commit into
mainfrom
fix/atomic-hook-mode

Conversation

@CryptoJones

Copy link
Copy Markdown
Owner

Summary

Fixes the transient "the guard hook is dead" blip: python3 omi-enforce.py failing with EACCES right after a re-provision.

Root cause: the managed-hook writers (omi-enforce.py, omi-guard.sh, omi-gate-reset.sh, git-fresh-base.sh, secret-output-guard.sh) wrote each script at mkstemp's 0600 default and set the exec bit in a separate dest.chmod(0o755) step — and omi-enforce.py never got a chmod at all. atomic_write_text already applies a mode to the temp file before the rename, but the writers never passed one. So when a re-provision runs as root and the B2 hardening then chowns the hook to root, that 0600 window (or the never-widened enforce hook) is unreadable by the agent user -> EACCES.

Fix: thread mode= through _write_managed/_write_if_absent into atomic_write_text, pass mode=0o755 at all five hook sites, and drop the now-redundant post-rename chmod. The destination lands 0755 atomically and is never briefly at 0600, so a subsequent chown root can't render it unreadable.

Verification

  • ruff check . -> clean
  • Full pytest -> 725 passed, 1 skipped
  • New regression test test_managed_hook_scripts_are_written_0755_atomically asserts every provisioned hook is 0o755 (fails if a writer reverts to the bare 0600 write).

Staged under [Unreleased]; the version bump/tag is a separate batched release step.

🤖 Generated with Claude Code

Proudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/

The hook writers wrote each script at mkstemp's 0600 default and set the exec bit in
a SEPARATE chmod step — and omi-enforce.py never got a chmod at all. When a
re-provision runs as root and the B2 guard-config hardening then chowns the hook to
root, that 0600 window (or the never-widened enforce hook) is unreadable by the agent
user, so `python3 omi-enforce.py` fails with EACCES mid-reprovision — the transient
"the guard hook is dead" blip.

Thread mode= through _write_managed/_write_if_absent into atomic_write_text (which
already applies the mode to the temp file BEFORE the rename), and drop the separate
post-rename dest.chmod(0o755) at all five hook sites. The destination is now never
briefly at 0600.

Adds a regression test asserting every provisioned hook is 0o755 (world-readable, so a
chown-root can't render it unreadable). Full suite: 725 passed, 1 skipped; ruff clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JFuGddPx3UhUkcC74KBXZB
CryptoJones added a commit that referenced this pull request Jul 2, 2026
Atomic-0o755 hook provisioning fix (#143): managed hook scripts get their mode set on
the temp file before the atomic rename, so a root-run re-provision never leaves a hook
briefly at 0600 (unreadable by the agent user after the B2 chown-root) — the transient
omi-enforce.py EACCES blip. Version 3.7.7 -> 3.7.8 (pyproject + __init__ + uv.lock);
CHANGELOG.

Full suite: 725 passed, 1 skipped; ruff clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JFuGddPx3UhUkcC74KBXZB
@CryptoJones CryptoJones merged commit fb9bf6e into main Jul 2, 2026
13 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant